package com.ccsoft.atools.service;

import com.ccsoft.atools.dao.RoadTripMapper;
import com.ccsoft.atools.model.RoadTrip;
import com.ccsoft.atools.utils.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName:RoadTripServiceImpl
 * @Description:TODO
 * @Author:chanchaw
 * @Date:2020-01-07 12:50
 * @Version:1.0
 **/
@Service
public class RoadTripServiceImpl implements RoadTripService {

    @Autowired
    private RoadTripMapper dao;

    @Override
    public int deleteByPrimaryKey(Integer iid) {
        return dao.deleteByPrimaryKey(iid);
    }

    @Override
    public int insert(RoadTrip record) {
        return dao.insert(record);
    }

    @Override
    public RoadTrip insertSelective(RoadTrip record) {
        int retDao = dao.insertSelective(record);
        if (retDao <= 0)
            throw BusinessException.instance("新增数据时出现异常");

        int pk = record.getIid();
        RoadTrip ret = selectByPrimaryKey(pk);
        System.out.println("重新查询后即将返回的对象是：" + ret.toString());
        return ret;
    }

    @Override
    public RoadTrip selectByPrimaryKey(Integer iid) {
        return dao.selectByPrimaryKey(iid);
    }

    @Override
    public RoadTrip updateByPrimaryKeySelective(RoadTrip record) {
        int retDao = dao.updateByPrimaryKeySelective(record);
        if (retDao <= 0)
            throw BusinessException.instance("修改数据时出现异常");

        return selectByPrimaryKey(record.getIid());
    }

    @Override
    public int updateByPrimaryKey(RoadTrip record) {
        return dao.updateByPrimaryKey(record);
    }

    @Override
    public List<RoadTrip> selectAll() {
        return dao.selectAll();
    }
}
